﻿/**
* ...
* @author alijayameilio
*/

package particling.force;

class LinearForce extends Force
{

	public var direction:Float;
	
	public function new(__x:Float, __y:Float, __power:Float, __direction:Float) 
	{
		super(__x, __y, __power);
		direction = __direction;
	}
	
	public override function getXForce(__xPos:Float, __yPos:Float):Float
	{
		var xForce:Float = 0;
		if (direction < 180)
		{
			xForce = 1 * Math.cos(Math.abs(direction - 90) * Math.PI / 180) * power;
		} else
		{
			xForce = -1 * Math.cos(Math.abs(270 - direction) * Math.PI / 180) * power;
		}
		return xForce;
	}
	public override function getYForce(__xPos:Float, __yPos:Float):Float
	{
		var yForce:Float = 0;
		if (direction < 180)
		{
			if (direction < 90)
			{
				yForce = -1 * Math.sin(Math.abs(direction - 90) * Math.PI / 180) * power;
			} else
			{
				yForce = 1 * Math.sin(Math.abs(direction - 90) * Math.PI / 180) * power;
			}
		} else
		{
			if (direction < 270)
			{
				yForce = 1 * Math.sin(Math.abs(270 - direction) * Math.PI / 180) * power;
			} else
			{
				yForce = -1 * Math.sin(Math.abs(270 - direction) * Math.PI / 180) * power;
			}
		}
		return yForce;
	}
}